import { Injectable } from '@angular/core';
import { HttpEvent, HttpInterceptor, HttpHandler, HttpRequest } from '@angular/common/http';
import { Observable } from 'rxjs';

/** Pass untouched request through to the next request handler. */
@Injectable()
export class NoopInterceptor implements HttpInterceptor {

  // 拦截并批量调整请求路径
  addApiToMockUrl(url: string){
    // if(/^mockapi/.test(url)){
    //   return `api/${url}`;
    // }
    return url;
  }

  intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
    // console.log('req === ', req);
    const secureReq = req.clone({
      url: this.addApiToMockUrl(req.url)
    });
    return next.handle(secureReq);
  }
}
